import {
  listColumns,
  columns,
  shipments,
  tabArr
} from './index.const';
import ElEditable from '@components/el-editable';
import {
  IndexService
} from './index.service';
import
tabs
from '@components/tabs/index.vue';
const indexService = new IndexService();
export default {
  components: {
    ElEditable,
    tabs
  },
  inject: ['apiMMallWeb'],
  data() {
    return {
      tableQuery: {
        supplierName: '',
        originalFactoryName: '',
        orderCode: '',
        orderStatus: null,
        commitDateEnd: '',
        commitDateStart: '',
        productLineCode: ''
      },
      commitDate: ['', ''],
      tableData: {},
      tableLoading: false,
      tabArr: tabArr,
      columns: columns,
      shipments: shipments,
      listColumns: listColumns,
      fullscreen: false,
      dialogVisible: false,
      delDialogVisible: false,
      errorMsgData: {},
      errorTableLoading: false,
      minDate: '',
      maxDate: '',
      payload: {},
      orderIds: '',
      // 产品线查询
      options: [],
      loading: false,
      // 主列表分页
      currentPage: 1,
      pageSize: 20,
      //检验失败列表分页
      errorCurrentPage: 1,
      errorPageSize: 20,
    };
  },
  created() {
    this.getList()
  },
  mounted() {},
  methods: {
    //tab切换
    handletabs(index) {
      if (index === 0) {
        this.tableQuery.orderStatus = null
      } else {
        this.tabArr.forEach((item, i) => {
          if (i === index) {
            this.tableQuery.orderStatus = item.val
          }
        })
      }
      this.queryFormQuery();
    },
    // 重置
    queryFormReset() {
      this.tableQuery = {
        supplierName: '',
        originalFactoryName: '',
        orderCode: '',
        orderStatus: '',
        commitDateEnd: '',
        commitDateStart: '',
        productLineCode: ''
      }
      this.commitDate = ['', '']
      this.currentPage = 1;
      this.getList()
    },
    // 查询
    async queryFormQuery() {
      this.currentPage = 1
      this.getList()
    },
    // 产品线搜索框
    async remoteMethod(val) {
      if (val) {
        this.loading = true
        let query = {
          busModel: 3,
          productLineName: val
        }
        let data = await this.apiMMallWeb.GetProductLineNameListV1ApiPOST({
          query: query
        });
        this.options = data
        this.loading = false
      }
    },
    async getList() {
      this.tableLoading = true
      const query = {
        busModel: 3,
        ...this.tableQuery,
        page: this.currentPage,
        pageSize: this.pageSize,

      };
      query.commitDateStart = this.commitDate[0]
      query.commitDateEnd = this.commitDate[1]
      const data = await this.apiMMallWeb.OrderDetailListOrderV1ApiPOST({
        query: query
      });
      this.tableLoading = false
      indexService.getStatusName(data.content);
      this.payload = data;
    },
    //主列表分页器
    reloadProductData(val) {
      this.currentPage = val.number
      this.pageSize = val.size
      this.getList()
    },
    onSubmit() {},
    // 校验失败弹窗
    showDialog(scope) {
      this.dialogVisible = true;
      this.errorListOrderId = scope.orderId
      this.getErrorList()
    },
    //效验失败列表
    async getErrorList() {
      this.errorTableLoading = true
      const data = await this.apiMMallWeb.PageListCheckFailMessageOrderV1ApiPOST({
        query: {
          orderId: this.errorListOrderId,
          page: this.errorCurrentPage,
          pageSize: this.errorPageSize
        }
      });
      if (data.content) {
        this.errorMsgData = data;
      }
      this.errorTableLoading = false
    },
    //检验失败分页器
    reloadError(val) {
      this.errorCurrentPage = val.number
      this.errorPageSize = val.size
      this.getErrorList()
    },
    // 高亮
    tableRowClassName({
      row,
      rowIndex
    }) {
      if (row.orderStatus === 1) {
        return 'warning-row';
      }
      return '';
    },
    //再次提交
    async resubmit(scope) {
      const data = await this.apiMMallWeb.OrderSubmitAgainOrderV1ApiPOST({
        mOrderQuery: {
          orderCode: scope.orderCode,
          orderId: scope.orderId,
          page: this.currentPage,
          pageSize: this.pageSize
        }
      });
      if (data === true) {
        this.$message.success('提交成功')
        this.getList()
      } else {
        this.$message.warning('提交失败')
      }
    },
    // 删除弹窗
    delDialog(scope) {
      this.delDialogVisible = true;
      this.orderIds = scope.orderId;
    },
    // 确认删除
    async delSure() {
      const data = await this.apiMMallWeb.DeleteOrderOrderV1ApiPOST({
        orderIds: this.orderIds
      });
      if (data === true) {
        this.$message.success('删除成功')
        this.getList();
      } else {
        this.$message.warning('删除失败')
      }
      this.delDialogVisible = false;
    },
    // 取消删除
    concelDel() {
      this.delDialogVisible = false;
    },
    //收货
    takeDialog(scope) {
      this.$router.push({
        path: '/purchase-order/surgery/receive',
        query: {
          orderId: row.orderId
        }
      });
    },
    //编辑
    async editGo(scope) {
      this.$router.push({
        path: '/purchase-order/surgery/add',
        query: {
          id: scope.orderId,
          detailid: scope.orderDetailId
        }
      });
    },
    //查看
    checkDetail(scope) {
      this.$router.push({
        path: '/purchase-order/surgery/detail',
        query: {
          id: scope.orderId
        }
      });
    }
  }
};